# -*- coding: utf-8 -*-
# @Time    : 2024/10/29 14:57
# @Author  : CHNJX
# @File    : config.py
# @Desc    : 基本配置文件
from datetime import timedelta
import os
from dotenv import load_dotenv

load_dotenv()


class Config:
    """Base configuration."""
    # Flask配置
    SECRET_KEY = os.getenv('SECRET_KEY', 'dev')

    # Jenkins配置 - 使用环境变量，同时提供默认值
    JENKINS_URL = os.getenv('JENKINS_URL', 'http://192.168.253.41:8080/')
    JENKINS_USER = os.getenv('JENKINS_USER', 'vp-tester')
    JENKINS_PASSWORD = os.getenv('JENKINS_PASSWORD', 'Aa123456')
    JENKINS_JOB_NAME = os.getenv('JENKINS_JOB_NAME', 'NVR_AUTO_TEST')
    PERFORMANCE_JOB_NAME = os.getenv('PERFORMANCE_JOB_NAME', 'performence_minitor')

    # 调度器配置
    SCHEDULER_API_ENABLED = True
    SCHEDULER_TIMEZONE = "Asia/Shanghaii"

    # 数据库
    MYSQL_HOST = os.getenv('MYSQL_HOST', '192.168.253.41')
    MYSQL_PORT = os.getenv('MYSQL_PORT', '3306')
    MYSQL_USER = os.getenv('MYSQL_USER', 'root')
    MYSQL_PASSWORD = os.getenv('MYSQL_PASSWORD', '123456')
    MYSQL_DATABASE = os.getenv('MYSQL_DATABASE', 'nvr_test')

    # SQLAlchemy配置
    SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    # 日志分析服务配置
    LOG_UPLOAD_DIR = os.getenv('LOG_UPLOAD_DIR', 'uploads/logs')
    LOG_RESULT_DIR = os.getenv('LOG_RESULT_DIR', 'uploads/results')
    MAX_CONTENT_LENGTH = int(os.getenv('MAX_CONTENT_LENGTH', 100 * 1024 * 1024))  # 100MB 默认最大文件大小


class DevelopmentConfig(Config):
    """Development configuration."""
    DEBUG = True


class ProductionConfig(Config):
    """Production configuration."""
    DEBUG = False


class TestingConfig(Config):
    """Testing configuration."""
    TESTING = True


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'testing': TestingConfig,
    'default': DevelopmentConfig
}